﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using MedicService.Domain.Directory;
using MedicService.Domain.Directory.Simple;
using MedicService.Server.Factory.Directory.Simple;
using MedicService.Server.Factory.Generic;

namespace MedicService.Server.Factory.Directory {
    public class JobFactory : DirectoryFactory<Job> {
        public JobFactory() : base("Job") { }

        protected override void FillEntity(Job entity, DataRow myDataRow) {
            entity.Id = (int) myDataRow["id"];
            entity.Title = (string) myDataRow["title"];

            entity.JobCategory = new JobCategoryFactory().Load(myDataRow["CategoryId"]);
        }

        protected override string GetInsertQuery(Job entity) {
            string q = "INSERT INTO [Job]"
                       + "           ([title]"
                       + "           ,[CategoryId])" 
                       + "     VALUES" 
                       + "           (" + Nullable(entity.Title) 
                       + "           ," + Nullable(entity.JobCategory) + "); "
                       + "";
            return q;
        }

        protected override string GetUpdateQuery(Job entity) {
            string q = "UPDATE [Job]"
                     + "   SET [title] = " + Nullable(entity.Title) 
                     + "      ,[CategoryId] = " + Nullable(entity.JobCategory) 
                     + " WHERE id" + entity.Id;
            return q;
        }

        protected override Job CreateEntity() {
            return new Job();
        }

    }
}